//
//  ViewController.m
//  TestChangeIcon
//
//  Created by 青梅睿创公司 on 2018/2/7.
//  Copyright © 2018年 青梅睿创公司. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
- (IBAction)snow:(id)sender;
- (IBAction)fine:(id)sender;
- (IBAction)cloud:(id)sender;
- (IBAction)littleRain:(id)sender;
- (IBAction)bigRain:(id)sender;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (IBAction)snow:(id)sender {
    [self setAppIconWithName:@"雪"];
}

- (IBAction)fine:(id)sender {
    [self setAppIconWithName:@"晴"];
}

- (IBAction)cloud:(id)sender {
    [self setAppIconWithName:@"多云"];
}

- (IBAction)littleRain:(id)sender {
    [self setAppIconWithName:@"小雨"];
}

- (IBAction)bigRain:(id)sender {
    [self setAppIconWithName:@"大雨"];
}

- (void)setAppIconWithName:(NSString *)iconName {
    if (![[UIApplication sharedApplication] supportsAlternateIcons]) {  // 是否支持动态替换
        NSLog(@"不支持动态替换图标");
        return;
    }
    
    if ([iconName isEqualToString:@""]) {
        iconName = nil;
    }
    [[UIApplication sharedApplication] setAlternateIconName:iconName completionHandler:^(NSError * _Nullable error) {
        if (error) {
            NSLog(@"更换app图标发生错误了 ： %@",error);
        }
    }];
}


@end
